package mobi.hami.huapin.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import mobi.hami.huapin.base.Result;
import mobi.hami.huapin.constants.BaseEnums;
import mobi.hami.huapin.dto.PageDTO;
import mobi.hami.huapin.dto.ProductForUserDTO;
import mobi.hami.huapin.dto.SPUDTO;
import mobi.hami.huapin.model.Product;
import mobi.hami.huapin.model.base.PageVO;
import mobi.hami.huapin.service.ProductForEndService;
import mobi.hami.huapin.service.ProductService;
import mobi.hami.huapin.service.SubjectService;
import mobi.hami.huapin.util.Results;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.Map;

@RestController
@RequestMapping(value = "/api/product", produces = "application/json")
@Api(description = "前端 商品api；")
public class ProductForeEndController {

    private static final Logger logger = LoggerFactory.getLogger(ProductForeEndController.class);

    @Autowired
    private ProductForEndService productForEndService;
    @Autowired
    private SubjectService subjectService;

    @RequestMapping(value = "/getuserfoodlist.do", method = RequestMethod.POST)
    @ApiOperation(value = "微信小程序获取商品列表（有subject_id 根据这个，没有根据周几）", notes = "{\n" +
            "  \"subject_id\": \"主题编号\",\n" +
            "  \"pageindex\": \"1\",\n" +
            "  \"pagesize\": \"20\",\n" +
            "  \"order_name\": \"id\",\n" +
            "  \"order_type\": \"asc\"\n" +
            "}")
    public Result getUserFoods(@RequestBody Map<String, Object> reqMap) {

        PageVO<ProductForUserDTO> pageVO =productForEndService.getListForUserByCountDownPool(reqMap);

        return Results.successWithData(pageVO, BaseEnums.SUCCESS.code(), BaseEnums.SUCCESS.desc());
    }



    @RequestMapping(value = "/getfirstlaunchfoods.do", method = RequestMethod.POST)
    @ApiOperation(value = "(大鸡)微信小程序获取首次拼团赠品列表")
    public Result getFirstLaunchFoods() {
        return Results.successWithData(subjectService.getSKUPreSentListBySubjectId(8), BaseEnums.SUCCESS.code(), BaseEnums.SUCCESS.desc());
    }

    @RequestMapping(value = "/getfirstpartackfoods.do", method = RequestMethod.POST)
    @ApiOperation(value = "（小鸡）微信小程序获取首次参团赠品列表")
    public Result getFirstPartackFoods() {
        return Results.successWithData(subjectService.getSKUPreSentListBySubjectId(9), BaseEnums.SUCCESS.code(), BaseEnums.SUCCESS.desc());
    }



    @RequestMapping(value = "/getspudata.do", method = RequestMethod.GET)
    @ApiOperation(value = "根据 spu获取商品的sku列表，销售属性,销售属性值）", notes = "")
    @ApiImplicitParams(
            {
                    @ApiImplicitParam(name = "spu_id", value = "spuid", example = "abc", paramType = "query", required = true, dataType = "Long"),
            }
    )
    public Result getSPUData(long spu_id) {

        SPUDTO spudto = productForEndService.getSpuData(spu_id);

        return Results.successWithData(spudto, BaseEnums.SUCCESS.code(), BaseEnums.SUCCESS.desc());
    }



}
